<?php

// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline){
    if (!(error_reporting() & $errno)) {
        // This error code is not included in error_reporting
        return;
    }

    switch ($errno) {
    	case E_ERROR:
	    case E_USER_ERROR:
	        $ret = "<b>My ERROR</b> [$errno] $errstr<br />\n";
	        $ret += "  Fatal error on line $errline in file $errfile";
	        $ret += ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
	        $ret += "Aborting...<br />\n";
	        break;
		case E_WARNING:
	    case E_USER_WARNING:
	        $ret = "<b>My WARNING</b> [$errno] $errstr<br />\n";
	        break;
	    case E_NOTICE:
	    case E_USER_NOTICE:
	        $ret = "<b>My NOTICE</b> [$errno] $errstr<br />\n";
	        break;
	    default:
	        $ret = "Unknown error type: [$errno] $errstr<br />\n";
	        break;
    }
    
    if (ini_get('log_errors'))error_log(sprintf("PHP %s:  %s in %s on line %d", $errors, $errstr, $errfile, $errline));
    
    Zend_Registry::get('console')->log('ErrorHand: '.$ret,Zend_Log::CRIT);
    
    $errno == E_USER_ERROR && exit(1);
        
    /* Don't execute PHP internal error handler */
    return true;
}
set_error_handler('myErrorHandler');

function myShutdown(){
	$isError = false;
	if ($error = error_get_last()){
		switch($error['type']){
			case E_ERROR:
			case E_CORE_ERROR:
			case E_COMPILE_ERROR:
			case E_USER_ERROR:
	        $isError = true;
	        break;
		}
	}
	if ($isError){
        Zend_Registry::get('console')->log('Shutdown: '.$error['message'],Zend_Log::CRIT);
	}
}
register_shutdown_function('myShutdown');

?>